<?php
/**
 * PostsModel
 * @author   songhuan <iphper@yeah.net>
 * @version   $Id: PostsModel.php 1 2011-06-20 01:11:00Z $
 */
class PostsModel extends CMysqlTable
{
	public static function model($className = __CLASS__)
	{
		return parent::model($className);
	}
	
	public $relations = array(
		'Categories' => array(self::BELONGS_TO, 'Categories', 'category_id'),
		'Users' => array(self::BELONGS_TO, 'Users', 'user_id')
	);
	
	public $rules = array(
		'post_title' => array(
			'required' => true,	
			'maxlength' => 50, 
			'when' => self::BOTH
		)
	);
	
	public $messages = array(
		'post_title' => array(
			'required' => '请填写文章标题',
			'maxlength' => '文章标题长度由小于50个字符组成'
		)
	);
	
	protected function preSave()
	{
		$this->dt_modify = date('Y-m-d H:i:s');
		$this->post_flags = implode(',', $this->post_flags);
	}
	
	public function preInsert()
	{
		$this->preSave();
		$this->user_id = $_SESSION['admin']->user_id;
		return true;
	}
	
	public function preUpdate()
	{
		$this->preSave();
		return true;
	}
}
